package com.leo.component;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.component.Component;
import com.almasb.fxgl.texture.AnimatedTexture;
import com.almasb.fxgl.texture.AnimationChannel;
import javafx.scene.layout.HBox;
import javafx.util.Duration;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-09  09:37
 * @Description: 展示分数
 */
public class ScoreShowComponent extends Component {

    private HBox box;

    private static int scoreT = 0;

    @Override
    public void onAdded() {
        AnimatedTexture texture = new AnimatedTexture(new AnimationChannel(FXGL.image("score/high.png"),
                10, 220 / 10, 28, Duration.seconds(.8), 0, 0));

        box = new HBox();
        box.getChildren().add(texture);
        entity.getViewComponent().addChild(box);
    }

    public void refreshScore(int score) {
        scoreT = scoreT + score;
        box.getChildren().clear();
        String[] value = String.valueOf(scoreT).split("");
        for (String s : value) {
            AnimatedTexture texture = new AnimatedTexture(new AnimationChannel(FXGL.image("score/high.png"),
                    10, 220 / 10, 28, Duration.seconds(.8), Integer.valueOf(s), Integer.valueOf(s)));
            box.getChildren().add(texture);
        }

        if (scoreT > 100) {
            FXGL.showMessage("你好棒");
        }
    }
}
